#!/usr/bin/env python
# -*- coding: utf-8 -*-

'labman2 /data URL dispatch rules'

from django.conf.urls import patterns, url
from labman2.data.views import (GroupListView, ClassListView,
                                DataGroupCreateView, UserGroupPermCreateView,
                                UserGroupPermView, UserGroupPermUpdateView)
from labman2.data.subdata.Link.views import (LinkCreateView, LinkUpdateView,
                                        LinkTypeCreateView, SubPropCreateView)
from labman2.data.dataviews import (DataListView, DataDetailView,
                                    DataCreateView, DataUpdateView,
                                    DataDeleteView)


urlpatterns = patterns('', # pylint: disable=C0103
    url(r'^$', 'labman2.data.views.index'),
    url(r'^openform/(?P<act>\w+)/$', 'labman2.data.views.openform'),
    url(r'^setdesktop/$', 'labman2.data.views.set_desktop'),
    url(r'^search/$', 'labman2.data.searchviews.search'),
    url(r'^advsearch/(?P<linecount>\d+)/$',
        'labman2.data.searchviews.advsearch'),
    #Groups, Classes, Data and permissions in groups, groups/data on desktop
    url(r'^grouplist/$', GroupListView.as_view()),
    url(r'^classlist/$', ClassListView.as_view()),
    url(r'^add/(?P<fmname>DataGroup)/$', DataGroupCreateView.as_view()),
    url(r'^adddesktop/GroupDeskTop/$', 'labman2.data.views.add_obj_desktop',
                                        {'tablename': 'GroupDeskTop'}),
    url(r'^adddesktop/DeskTop/$', 'labman2.data.views.add_obj_desktop',
                                        {'tablename': 'DeskTop'}),
    url(r'^adddesktop/ClassDeskTop/$', 'labman2.data.views.add_obj_desktop',
                                        {'tablename': 'ClassDeskTop'}),
    #UserGroupPerm generic views
    url(r'^permingroups/$', UserGroupPermView.as_view()),
    url(r'^add/(?P<fmname>UserGroupPerm)/$', UserGroupPermCreateView.as_view()),
    url(r'^edit/(?P<fmname>UserGroupPerm)/(?P<pk>\d+)/$',
                                            UserGroupPermUpdateView.as_view()),
)

urlpatterns += patterns('',
    #Link,
    url(r'^add/(?P<fmname>Link)/$', LinkCreateView.as_view(), name='add-link'),
    url(r'^add/(?P<fmname>Link)/(?P<subjid>\d*)/(?P<properid>\d*)/'
        r'(?P<ltypeid>\d+)/$', LinkCreateView.as_view(), name='add-link-init'),
    url(r'^edit/(?P<fmname>Link)/(?P<pk>\d+)/$', LinkUpdateView.as_view()),
    #LinkType
    url(r'^add/(?P<fmname>LinkType)/(?P<subjid>\d*)/(?P<properid>\d*)/'
        r'(?P<ltypename>[\w-]+)/$', LinkTypeCreateView.as_view(),
        name='add-linktype-init'),
)

urlpatterns += patterns('',
    #Data generic Views
    url(r'^datalist/$', DataListView.as_view()),
    url(r'^add/(?P<fmname>\w+)/$', DataCreateView.as_view()),
    url(r'^add/(?P<fmname>\w+)/(?P<tolink>\d+)/$', SubPropCreateView.as_view()),
    url(r'^edit/(?P<fmname>\w+)/(?P<pk>\d+)/$', DataUpdateView.as_view()),
    url(r'^delete/(?P<fmname>\w+)/(?P<pk>\d+)/$',
                                        'labman2.data.dataviews.markdelete'),
    url(r'^undelete/(?P<fmname>\w+)/(?P<pk>\d+)/$',
                                            'labman2.data.dataviews.restore'),
    url(r'^destroy/(?P<fmname>\w+)/(?P<pk>\d+)/$', DataDeleteView.as_view()),
    url(r'^base/(?P<pk>\d+)/$', DataDetailView.as_view()),
)

#translation tools
js_info_dict = {
    'packages': ('labman2',)
}
urlpatterns += patterns('',
    (r'^tools/i18n/setlang/(?P<lng>.{2,})/$',
                                            'labman2.viewtools.views.setlang'),
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
    (r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
)

